package com.kaifamiao.month05.day10;

import lombok.Data;

import java.io.IOException;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.UUID;

public class Client1 {

    public static void main(String[] args) throws IOException {

        Socket client = new Socket("localhost",9999);
        String name = UUID.randomUUID().toString();
        System.out.println(name + "已经登录！");
        client.getOutputStream().write(name.getBytes(StandardCharsets.UTF_8));
//        client.shutdownOutput();
        System.out.println("请输入群发内容:");
        Scanner in = new Scanner(System.in);
        String message = in.nextLine();
        // 将客户端的内容写到服务端
        client.getOutputStream().write(message.getBytes(StandardCharsets.UTF_8));
        client.shutdownOutput();
        // 将服务端的内容读到客户端
        byte[] result = client.getInputStream().readAllBytes();
        System.out.println("服务端的反馈：" + new String(result));
    }
}


